package edu.tyut.game.ui.learn

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.switchMap
import edu.tyut.game.logic.PoemRepository

class LearnViewModel : ViewModel() {

    private val dynastiesListLiveData = MutableLiveData<List<String>>()
    val dynastiesList = dynastiesListLiveData.switchMap {
        PoemRepository.getDynasties()
    }
    fun getDynastiesList(){
        dynastiesListLiveData.value = dynastiesListLiveData.value
    }

    // 发送请求
    private val poemListLiveData = MutableLiveData<String>()
    val poemList = poemListLiveData.switchMap {
        PoemRepository.getPoemListByDynasty(it)
    }
    fun getPoemListByDynasty(dynasty: String){
        poemListLiveData.value = dynasty
    }

    // 发送搜索请求
    private val searchPoemListLiveData = MutableLiveData<String>()
    val searchPoemList = searchPoemListLiveData.switchMap {
        PoemRepository.getPoemListBySearch(it)
    }
    fun getSearchPoemListByContent(content: String){
        searchPoemListLiveData.value = content
    }

    // 诗词推荐埋点
    private val idsLiveData = MutableLiveData<String>()
    val res = idsLiveData.switchMap {
        PoemRepository.poemRecommend(it)
    }
    fun poemRecommend(ids: String){
        idsLiveData.value = ids
    }

    // 诗词推荐TOP N
    private val topLiveData = MutableLiveData<Int>()
    val resTop = topLiveData.switchMap {
        PoemRepository.getPoemOrderByClickCount()
    }
    fun getPoemOrderByClickCount(){
        topLiveData.value = topLiveData.value
    }
}